package com.dly.blog.controller;

import com.dly.blog.domain.GptSessionContent;
import com.dly.blog.domain.dto.MessageContentDto;
import com.dly.blog.domain.ro.ChatGptRO;
import com.dly.blog.domain.vo.GptSessionVO;
import com.dly.blog.msg.R;
import com.dly.blog.service.GptSessionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gptSession")
@RequiredArgsConstructor
@Tag(name = "gpt的聊天会话模块")
@Slf4j
public class GptSessionController extends BaseController{

    private final GptSessionService gptSessionService;

    @PostMapping("/create")
    @Operation(summary = "信息保存接口 保存完整的一次会话")
    public ResponseEntity<R<String>> save(@RequestBody @Validated ChatGptRO chatGptRO, BindingResult br){
        return operate(()-> this.successDate(gptSessionService.createGptSession(chatGptRO)), br);
    }

    @GetMapping("/list")
    @Operation(summary = "会话列表接口")
    public ResponseEntity<R<List<GptSessionVO>>> getList(){
        return operate(()-> this.successDate(gptSessionService.getList()));
    }

    @PostMapping("/del")
    @Operation(summary = "会话删除接口")
    public ResponseEntity<R<Void>> delete(@RequestParam("sessionId") @NotEmpty(message= "会话id不能为空") String sessionId){
        gptSessionService.delete(sessionId);
        return operate(this::success);
    }

    @GetMapping("/contentList")
    @Operation(summary = "会话内容接口")
    public ResponseEntity<R<List<MessageContentDto>>> getContent(@RequestParam("sessionId") @NotEmpty(message= "会话id不能为空") String sessionId){
        return operate(()-> this.successDate(gptSessionService.getContent(sessionId)));
    }

    @GetMapping("/historyNum")
    @Operation(summary = "获取历史记录次数")
    public ResponseEntity<R<Integer>> getHistoryNum(){
        return operate(()-> this.successDate(gptSessionService.getHistoryNum()));
    }


}
